home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / FeatureDescriptor.java < prev    next >
Text File  |  1998-09-22  |  6KB  |  208 lines

  1. /*
  2.  * @(#)FeatureDescriptor.java    1.16 98/07/01
  3.  *
  4.  * Copyright 1996-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.beans;
  16.  
  17. /**
  18.  * The FeatureDescriptor class is the common baseclass for PropertyDescriptor,
  19.  * EventSetDescriptor, and MethodDescriptor, etc.
  20.  * <p>
  21.  * It supports some common information that can be set and retrieved for
  22.  * any of the introspection descriptors.
  23.  * <p>
  24.  * In addition it provides an extension mechanism so that arbitrary
  25.  * attribute/value pairs can be associated with a design feature.
  26.  */
  27.  
  28. public class FeatureDescriptor {
  29.  
  30.  
  31.     public FeatureDescriptor() {
  32.     }
  33.  
  34.     /**
  35.      * @return The programmatic name of the property/method/event
  36.      */
  37.     public String getName() {
  38.     return name;
  39.     }
  40.  
  41.     /**
  42.      * @param name  The programmatic name of the property/method/event
  43.      */
  44.     public void setName(String name) {
  45.     this.name = name;
  46.     }
  47.  
  48.     /**
  49.      * @return The localized display name for the property/method/event.
  50.      *    This defaults to the same as its programmatic name from getName.
  51.      */
  52.     public String getDisplayName() {
  53.     if (displayName == null) {
  54.         return getName();
  55.     }
  56.     return displayName;
  57.     }
  58.  
  59.     /**
  60.      * @param displayName  The localized display name for the
  61.      *        property/method/event.
  62.      */
  63.     public void setDisplayName(String displayName) {
  64.     this.displayName = displayName;
  65.     }
  66.  
  67.     /**
  68.      * The "expert" flag is used to distinguish between those features that are
  69.      * intended for expert users from those that are intended for normal users.
  70.      *
  71.      * @return True if this feature is intended for use by experts only.
  72.      */
  73.     public boolean isExpert() {
  74.     return expert;
  75.     }
  76.  
  77.     /**
  78.      * The "expert" flag is used to distinguish between features that are
  79.      * intended for expert users from those that are intended for normal users.
  80.      *
  81.      * @param expert True if this feature is intended for use by experts only.
  82.      */
  83.     public void setExpert(boolean expert) {
  84.     this.expert = expert;
  85.     }
  86.  
  87.     /**
  88.      * The "hidden" flag is used to identify features that are intended only
  89.      * for tool use, and which should not be exposed to humans.
  90.      *
  91.      * @return True if this feature should be hidden from human users.
  92.      */
  93.     public boolean isHidden() {
  94.     return hidden;
  95.     }
  96.  
  97.     /**
  98.      * The "hidden" flag is used to identify features that are intended only
  99.      * for tool use, and which should not be exposed to humans.
  100.      *
  101.      * @param hidden  True if this feature should be hidden from human users.
  102.      */
  103.     public void setHidden(boolean hidden) {
  104.     this.hidden = hidden;
  105.     }
  106.  
  107.     /**
  108.      * @return  A localized short description associated with this 
  109.      *   property/method/event.  This defaults to be the display name.
  110.      */
  111.     public String getShortDescription() {
  112.     if (shortDescription == null) {
  113.         return getDisplayName();
  114.     }
  115.     return shortDescription;
  116.     }
  117.  
  118.     /**
  119.      * You can associate a short descriptive string with a feature.  Normally
  120.      * these descriptive strings should be less than about 40 characters.
  121.      * @param text  A (localized) short description to be associated with
  122.      * this property/method/event.
  123.      */
  124.     public void setShortDescription(String text) {
  125.     shortDescription = text;
  126.     }
  127.  
  128.     /**
  129.      * Associate a named attribute with this feature.
  130.      * @param attributeName  The locale-independent name of the attribute
  131.      * @param value  The value.
  132.      */
  133.     public void setValue(String attributeName, Object value) {
  134.     if (table == null) {
  135.         table = new java.util.Hashtable();
  136.     }
  137.     table.put(attributeName, value);
  138.     }
  139.  
  140.     /**
  141.      * Retrieve a named attribute with this feature.
  142.      * @param attributeName  The locale-independent name of the attribute
  143.      * @return  The value of the attribute.  May be null if
  144.      *       the attribute is unknown.
  145.      */
  146.     public Object getValue(String attributeName) {
  147.     if (table == null) {
  148.        return null;
  149.     }
  150.     return table.get(attributeName);
  151.     }
  152.  
  153.     /**
  154.      * @return  An enumeration of the locale-independent names of any 
  155.      *    attributes that have been registered with setValue.
  156.      */
  157.     public java.util.Enumeration attributeNames() {
  158.     if (table == null) {
  159.         table = new java.util.Hashtable();
  160.     }
  161.     return table.keys();
  162.     }
  163.  
  164.     /**
  165.      * Package-private constructor,
  166.      * Merge information from two FeatureDescriptors.
  167.      * The merged hidden and expert flags are formed by or-ing the values.
  168.      * In the event of other conflicts, the second argument (y) is
  169.      * given priority over the first argument (x).
  170.      * @param x  The first (lower priority) MethodDescriptor
  171.      * @param y  The second (higher priority) MethodDescriptor
  172.      */
  173.     FeatureDescriptor(FeatureDescriptor x, FeatureDescriptor y) {
  174.     expert = x.expert | y.expert;
  175.     hidden = x.hidden | y.hidden;
  176.     name = y.name;
  177.     shortDescription = x.shortDescription;
  178.     if (y.shortDescription != null) {
  179.         shortDescription = y.shortDescription;
  180.     }
  181.     displayName = x.displayName;
  182.     if (y.displayName != null) {
  183.         displayName = y.displayName;
  184.     }
  185.     addTable(x.table);
  186.     addTable(y.table);
  187.     }
  188.  
  189.     private void addTable(java.util.Hashtable t) {
  190.     if (t == null) {
  191.         return;
  192.     }
  193.     java.util.Enumeration keys = t.keys();
  194.     while (keys.hasMoreElements()) {
  195.         String key = (String)keys.nextElement();
  196.         Object value = t.get(key);
  197.         setValue(key, value);
  198.     }
  199.     }
  200.  
  201.     private boolean expert;
  202.     private boolean hidden;
  203.     private String shortDescription;
  204.     private String name;
  205.     private String displayName;
  206.     private java.util.Hashtable table;
  207. }
  208.